package io.shmilyhe.cloud.client;


import io.netty.channel.ChannelHandlerContext;
import io.shmilyhe.cloud.client.api.IWSEvent;
import io.shmilyhe.cloud.client.api.IWsHandler;

public class WsHandler implements IWsHandler{
    private IWSEvent active;
    private IWSEvent inActive;
    private IWSEvent closed;
    private IWSEvent exception;
    private IWSEvent message;

    
    public void setActive(IWSEvent active) {
        this.active = active;
    }
    public void setInActive(IWSEvent inActive) {
        this.inActive = inActive;
    }
    public void setClosed(IWSEvent closed) {
        this.closed = closed;
    }
    public void setException(IWSEvent exception) {
        this.exception = exception;
    }
    public void setMessage(IWSEvent message) {
        this.message = message;
    }

    protected void printInfo(String str){
        System.out.println(str);
    }
    @Override
    public void onActive(ChannelHandlerContext ctx, String msg) {
        if(active==null){
            printInfo(msg);
        }else
        active.onEvent(ctx, msg);
    }
    @Override
    public void onInActive(ChannelHandlerContext ctx,String msg) {
        if(inActive==null){
            printInfo(msg);
        }else
        inActive.onEvent(ctx, msg);
    }
    @Override
    public void onException(ChannelHandlerContext ctx, String msg) {
        if(exception==null){
            printInfo(msg);
        }else
        exception.onEvent(ctx, msg);
    }
    @Override
    public void onClosed(ChannelHandlerContext ctx, String msg) {
        if(closed==null){
            printInfo(msg);
        }else
        closed.onEvent(ctx, msg);
    }
    @Override
    public void onMessage(ChannelHandlerContext ctx, String msg) {
        if(message==null){
            printInfo(msg);
        }else
        message.onEvent(ctx, msg);
    }
   
    

   
    
}
